package tf2pickup;

import java.util.ArrayList;

import tf2pickup.exceptions.FaultyConfigurationFile;

/**
 * Represents the configuration of the bot. This class will be initiated by a
 * file parser that reads the file and passes the content to the constructor.
 * @author Philipp Preß
 */
public class Config {

    public boolean botVerbose;
    public boolean botAutoNickChange;
    public boolean botLog;
    public String mumbleServer;
    public int mumblePort;
    public String mumblePassword;
    public String ircServer;
    public int ircPort;
    public String ircNickname;
    public String ircChannel;
    public String ircChannelPassword;
    public String ircAuthNickname;
    public String ircAuthPassword;
    public ArrayList<GameServer> servers;
    public ArrayList<String> maps;

    /**
     * Checks if all necessary settings are existent. If any invalid properties 
     * where found, this method corrects them by setting default values where 
     * possible.
     * (e.g. ircPort = 6667).
     * @throws FaultyConfigurationFile if a necessary value / property is 
     * missing in the configuration file.
     */
    public void checkConfig() throws FaultyConfigurationFile {
        if (this.ircServer == null) {
            throw new FaultyConfigurationFile("Value of property 'ircServer' is invalid.");
        }
        if (this.ircChannel == null) {
            throw new FaultyConfigurationFile("Value of property 'ircChannel' is invalid.");
        }
        if (this.ircAuthNickname == null) {
            throw new FaultyConfigurationFile("Value of property 'ircAuthNickname' is invalid.");
        }
        if (this.ircAuthPassword == null) {
            throw new FaultyConfigurationFile("Value of property 'ircAuthPassword' is invalid.");
        }
        if (this.mumbleServer == null) {
            throw new FaultyConfigurationFile("Value of property 'mumbleServer' is invalid.");
        }
        if (this.mumblePort == 0) {
            throw new FaultyConfigurationFile("Value of property 'mumblePort' is invalid.");
        }
        if (this.maps == null) {
            throw new FaultyConfigurationFile("Value of property 'maps' is invalid.");
        }
        if (this.ircPort == 0) {
            this.ircPort = 6667;
        }

        if (this.servers == null) {
            throw new FaultyConfigurationFile("Value of property 'servers' is invalid.");
        }
        if (this.maps.isEmpty()) {
            throw new FaultyConfigurationFile("Value of property 'maps' is invalid.");
        }
    }
}